<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:include page="template-head.jsp" />
<script type="text/javascript">
 function change(){
	 var daycheck = $(".nbinChoice");
	 var num = $(".nbinChoice").length; 	
 }
</script>
<jsp:include page="template-body.jsp"/>
<div class="hero-unit">
<div id="viewquestionpage">
<div class="container">
	<jsp:include page="errors.jsp"/>
	<p>Question of survey titled ${survey.title}</p>
	<div>
	<div id="viewquestionpagebody">
	<c:choose>
		<%-- Case for Binary type questions --%>
		<c:when test="${question.type == 1}">
			<form id="binaryquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td><input type="radio" name="binChoice" class="btn btn-primary" value="1"> ${binaryq.yes}</td>
						<td><input type="radio" name="binChoice" class="btn btn-primary" value="0"> ${binaryq.no}</td>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for Numeric type questions --%>
		<c:when test="${question.type == 2}">
			<form id="numericquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
					<tr>
						<td>You may enter any number between ${numericq.min} and ${numericq.max}.</td>
					</tr>
				</table>
				<table>
					<tr>
						<td>Numeric Answer: <input type="text" name="answer"></td>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for open ended type questions --%>
		<c:when test="${question.type == 3}">
			<form id="openendedquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td><textarea name="answer" rows="10" cols="100">Type your answer here.</textarea></td>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for likert type questions --%>
		<c:when test="${question.type == 4}">
			<form id="likertquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td>${likertq.choice1}</td>
						<td>${likertq.choice2}</td>
						<td>${likertq.choice3}</td>
						<td>${likertq.choice4}</td>
						<td>${likertq.choice5}</td>
						<c:if test="${likertq.numChoices == 7}">
						<td>${likertq.choice6}</td>
						<td>${likertq.choice7}</td>
						</c:if>
					</tr>
					<tr>
						<c:choose>
							<c:when test="${likertq.type == 1}">
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="1"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="2"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="3"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="4"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="5"></td>
								<c:if test="${likertq.numChoices == 7}">
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="6"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="7"></td>
								</c:if>
							</c:when>
							<c:otherwise>
								<c:if test="${likertq.numChoices == 7}">
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="-3"></td>
								</c:if>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="-2"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="-1"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="0"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="1"></td>
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="2"></td>
								<c:if test="${likertq.numChoices == 7}">
								<td><input type="radio" name="likertChoice" class="btn btn-primary" value="3"></td>
								</c:if>
							</c:otherwise>
						</c:choose>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for multiple choice type questions --%>
		<c:when test="${question.type == 5}">
			<form id="openendedquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<c:forEach var="choices" items="${multiplechoiceq}">
					<tr>
						<td><input type="radio" name="choice" class="btn btn-primary" value="${choices.pos}"> ${choices.choiceDesc}</td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for multiple selection type questions --%>
		<c:when test="${question.type == 6}">
			<form id="multipleselectionquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<c:forEach var="choices" items="${multiplechoiceq}">
					<tr>
						<td><input type="checkbox" name="choice" value="${choices.choiceDesc}"> ${choices.choiceDesc}</td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for rank order type questions --%>
		<c:when test="${question.type == 7}">
			<form id="rankorderquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<p>Please enter a number on the space provided below next to the choices. 1 is the highest rank.</p>
				<table>
					<c:forEach var="choices" items="${multiplechoiceq}">
					<tr>
						<td><input type="text" name="${choices.choiceDesc}"> ${choices.choiceDesc}</td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for continuous type questions --%>
		<c:when test="${question.type == 8}">
			<form id="continuousquestionform" method="post" action="viewsurvey.do" oninput="output.value=parseInt(answer.value)">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td><input name="answer" type="range" min="${continuousq.min}" max="${continuousq.max}" step="${continuousq.step}">
							<output name="output" for="answer"></output></td>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for network binary list type questions --%>
		<c:when test="${question.type == 9}">
			<form id="networkbinaryquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<c:forEach var="entity" items="${entitylist}">
					<tr>
						<td><input type="checkbox" name="nbinChoice" class= "nbinChoice" onclick= "change()" value="${entity.name}"> ${entity.name}</td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for network open list type questions --%>
		<c:when test="${question.type == 10}">
			<form id="networkopenquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td><p>When writing your answer, make sure you separate it by comma. All other separation will be ignored.</p></td>
					</tr>
					<tr>
						<td><textarea name="answer" rows="10" cols="100">Type your answer here.</textarea></td>
					</tr>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for network weighted list type questions --%>
		<c:when test="${question.type == 11}">
			<form id="networkweightedquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<tr>
						<td></td>
						<c:forEach var="choices" items="${multiplechoiceq}">
							<td>${choices.choiceDesc}</td>
						</c:forEach>
					</tr>
					<c:forEach var="entity" items="${entitylist}">
						<tr>
							<td>${entity.name}</td>
							<c:forEach var="choices" items="${multiplechoiceq}">
								<td><input type="radio" name="${entity.name}" value="${choices.weight}"></td>
							</c:forEach>
						</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for network weighted continuous list type questions --%>
		<c:when test="${question.type == 12}">
			<script type="text/javascript">
			function showValue(newValue, id) {
				document.getElementById(id).innerHTML=newValue;
			}
			</script>
			<form id="networkweightedcontinuousquestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<c:forEach var="entity" items="${entitylist}">
					<tr>
						<td>${entity.name}</td>
						<td><input type="range" name="${entity.name}" min="${continuousq.min}"
						           max="${continuousq.max}" step="${continuousq.step}" onchange="showValue(this.value, '${entity.name}_value')">
						    <span id="${entity.name}_value">0</span></td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for network rank order type questions --%>
		<c:when test="${question.type == 13}">
			<form id="networkrankorderquestionform" method="post" action="viewsurvey.do">
				<p>Please enter a value between 1 and ${rankorderq.pos} for fields below. If there are more than ${rankorderq.pos} fields,
				Leave the remaining fields blank. Make sure that there are no duplicate numbers entered in the field.</p><br/><br/>
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
				</table>
				<table>
					<c:forEach var="entity" items="${entitylist}">
					<tr>
						<td><input type="text" name="${entity.name}">${entity.name}</td>
					</tr>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:when>
		
		<%-- Case for socio-cognitive network list type questions --%>
		<c:otherwise>
			<form id="sociocognitivequestionform" method="post" action="viewsurvey.do">
				<table>
					<tr>
						<td>${question.qnum}. ${question.question}</td>
					</tr>
					<c:forEach var="entitysource" items="${entitylistsource}">
					<tr>
						<td><b>${entitysource.name}</b></td>
					</tr>
						<c:forEach var="entitytarget" items="${entitylisttarget}">
						<tr>
							<td>${entitytarget.name}</td>
							<td><input type="checkbox" name="${entitysource.name}" class= "nbinChoice" onclick= "change()" value="${entitytarget.name}"></td>
						</tr>
						</c:forEach>
					</c:forEach>
				</table>
				<table>
					<tr>
						<c:if test="${question.qnum > 1}">
							<td><input type="submit" name="button" class="btn btn-success" value="Previous Question"></td>
						</c:if>
						<c:if test="${question.qnum < maxqnum}">
							<td><input type="submit" name="button" class="btn btn-success" value="Next Question"></td>
						</c:if>
						<c:if test="${question.qnum == maxqnum && user.type == 3}">
							<td><input type="submit" name="button" class="btn btn-success" value="Submit Answer and Return to List">
						</c:if>
						<td><input type="submit" name="button" class="btn btn-inverse" value="Go Back to List of Questions"></td>
					</tr>
				</table>
			</form>
		</c:otherwise>
	</c:choose>
	</div>
	</div>
</div>
</div>
</div>
<!--Create another space for contents' extension  -->
	<div class="container2">
	
	
 	</div>
<jsp:include page="template-foot.jsp" /> 